function mirrorTree(root: TreeNode | null): TreeNode | null {
    if (!root) {
        return null;
    }
    let list: TreeNode[] = new Array<TreeNode>();
    list.push(root);

    let node;
    while (list.length > 0) {
        node = list.pop();
        if (node != null) {
            let temp = node.left;
            node.left = node.right;
            node.right = temp;
            if(node.left){
                list.push(node.left);
            }
            if(node.right){
                list.push(node.right);
            }
        }
    }
    return root;
};